#include "parser.h"
#include "error.h"
#include "lexer.h"
#include <iostream>
#include <sstream>
using namespace std;

istream* input; //pointer to input stream
int main(int argc, char* argv[])
{
    switch(argc){
    case 1:
        input = &cin;
        break;
    case 2:
        input = new istringstream(argv[1]);
        break;
    default:
        Error::error("You give me too many arguments!");
        return 1;
    }
    Lexer::table["pi"] = 3.1415926535897932385;
    Lexer::table["e"]= 2.7182818284590452354;
    while(*input){
        Lexer::get_token();
        if(Lexer::curr_tok == Lexer::END)break;
        if(Lexer::curr_tok == Lexer::PRINT)continue;
        cout << Parser::expr(false) << endl;
    }
    if(input != &cin) delete input;
    return Error::no_of_errors;
}
